package org.infermq.common;

import java.io.IOException;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.support.PropertiesLoaderSupport;

public class InferMQConfigParser extends PropertiesLoaderSupport implements
		ApplicationContextAware {

	public InferMQConfig getMQConfig() throws IOException {
		return getConfig(mergeProperties());

	}

	private InferMQConfig getConfig(Properties _props) {
		InferMQConfig config = new InferMQConfig();
		config.setDataDir(_props.getProperty(LUCENE_DATA_DIR));
		config.setJmsServers(_props.getProperty(JMS_SERVERS));
		config.setBroadcastQueue(_props.getProperty(BROADCAST_QUEUE));
		return config;

	}

	private static final String LUCENE_DATA_DIR = "lucene.data.dir";

	private static final String JMS_SERVERS = "jms.servers";

	private static final String BROADCAST_QUEUE = "broadcast.queue";

	@Override
	public void setApplicationContext(ApplicationContext _ctx)
			throws BeansException {
		this.ctx = _ctx;
	}

	private ApplicationContext ctx;

}
